<script lang="ts" setup name="AppTopnav">
import useStore from '@/store'
import router from '@/router'
import Message from './message'
import Confirm from '@/components/confirm'
const { user } = useStore()
const logout = async () => {
  // 清除信息
  await Confirm({
    title: '温馨提示',
    text: '你确定要退出吗?'
  })
  user.logout()
  router.push('/login')
  Message.success('退出成功')
}
</script>

<template>
  <nav class="app-topnav">
    <div class="container">
      <ul>
        <template v-if="user.userInfo.account">
          <li>
            <a href="javascript:;">
              <i class="iconfont icon-user"></i>
              {{ user.userInfo.nickname || user.userInfo.account }}
            </a>
          </li>
          <li><a @click="logout" href="javascript:;">退出登录</a></li>
        </template>
        <template v-else>
          <li><router-link to="/login">请先登录</router-link></li>
          <li><router-link to="/">免费注册</router-link></li>
        </template>
        <li><RouterLink to="/member/order">我的订单</RouterLink></li>
        <li><RouterLink to="/member">会员中心</RouterLink></li>
        <li><a href="javascript:;">帮助中心</a></li>
        <li><a href="javascript:;">关于我们</a></li>
        <li>
          <a href="javascript:;">
            <i class="iconfont icon-phone"></i>
            手机版
          </a>
        </li>
      </ul>
    </div>
  </nav>
</template>

<style scoped lang="less">
.app-topnav {
  background: #333;

  ul {
    display: flex;
    height: 53px;
    justify-content: flex-end;
    align-items: center;

    li {
      a {
        padding: 0 15px;
        color: #cdcdcd;
        line-height: 1;
        display: inline-block;

        i {
          font-size: 14px;
          margin-right: 2px;
        }

        &:hover {
          color: @xtxColor;
        }
      }

      ~ li {
        a {
          border-left: 2px solid #666;
        }
      }
    }
  }
}
</style>
